package fluxx.draft;

public class RuleSet {
	public int playAmount, drawAmount, handLimit, keeperLimit;
	
	public RuleSet() {
		defaultPlayAmount();
		defaultDrawAmount();
		defaultHandLimit();
		defaultKeeperLimit();
	}
	
	public void defaultPlayAmount() { this.playAmount = 1; }
	public void defaultDrawAmount() { this.drawAmount = 1; }
	public void defaultHandLimit() { this.handLimit = -1; }
	public void defaultKeeperLimit() {this.keeperLimit = -1; }
	public void applyLimits(GameState game) {
		// keeper limit
		if (keeperLimit >= 0) {
			int keeperDiff;
			for (Player player : game.players) {
				keeperDiff = player.getKeepers().size() - keeperLimit;
				if (keeperDiff > 0) {
					AbstractCardSet cardsToDiscard = game.demandPick(player.getKeepers(), keeperDiff, "Keeper Limit");
					for (Card card : cardsToDiscard) {
						player.getKeepers().remove(card);
						game.discard(card);
					}
				}
			}
		}
		// hand limit
		if (handLimit >= 0) {
			int handDiff;
			for (Player player : game.players) {
				handDiff = player.getHand().size() - handLimit;
				if (handDiff > 0) {
					game.demandPick(player.getHand(), handDiff, "Hand Limit");
				}
			}
		}
	}
}
